home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / ATARI_RF.C < prev    next >
C/C++ Source or Header  |  1989-06-08  |  4KB  |  140 lines

  1. /*
  2.  * In-memory resource file fixup routine.
  3.  * Copyright (C) 1987 by R.E. Janssen.
  4.  *
  5.  * Insert proper include filename and compile it as a separate module.
  6.  * Make sure the name of the external vars agrees with the main program.
  7.  *
  8.  * Call rsrc_fixup during init, before using the resource.
  9.  *
  10.  * The number of dirty type-conversions and recasts is really awful!!
  11.  *
  12.  */
  13.  
  14. #include <gemstuff.h>            /* everything we need to know about GEM */
  15.  
  16. #include "atari_rs.c"            /* get resource definitions */
  17.  
  18.  
  19. /*** GLOBAL VARIABLES FROM MAIN PROGRAM ***/
  20.  
  21. extern WORD gr_hhchar,gr_hwchar,gr_hhbox,gr_hwbox;/* system font sizes */
  22.  
  23.  
  24. /*
  25.  * fixup the complete resource, as loaded with the includes
  26.  *
  27.  * this consists of:
  28.  * - changing indices to addresses (pointers)
  29.  * - converting units from characters to pixels
  30.  *
  31.  * dirty trick:
  32.  * any resource tree that's OUTLINED will be converted to screen
  33.  * resolution, others will get a standard conversion.
  34.  * this way, one can display icons in a window on all resolutions,
  35.  * and still get dialog boxes converted properly.
  36.  */
  37.  
  38. #define fixsize(x,s,t)       x = ((x & 0xff) * s + (x >> 8) / t)
  39.  
  40. void rsrc_fixup ()
  41.  
  42. {
  43.    register int i;
  44.    register OBJECT *object;
  45.    WORD xscale,yscale,ytrim;        /* object scaling factor */
  46.  
  47.    /* start converting all indices to addresses, type by type */
  48.  
  49. #if NUM_BB != 0
  50.    for (i = 0; i < NUM_BB; i++)        /* put bitblock addresses */
  51.       rs_bitblk[i].bi_pdata = rs_imdope[(int) rs_bitblk[i].bi_pdata].image;
  52. #endif
  53.  
  54. #if NUM_FRIMG != 0
  55.    for (i = 0; i < NUM_FRIMG; i++)    /* put image addresses */
  56.       rs_frimg[i] = rs_imdope[(int) rs_frimg[i]].image;
  57. #endif
  58.  
  59. #if NUM_IB != 0
  60.    for (i = 0; i < NUM_IB; i++)        /* put icon addresses */
  61.    {
  62.       rs_iconblk[i].ib_pmask = rs_imdope[(int) rs_iconblk[i].ib_pmask].image;
  63.       rs_iconblk[i].ib_pdata = rs_imdope[(int) rs_iconblk[i].ib_pdata].image;
  64.       rs_iconblk[i].ib_ptext = rs_strings[(int) rs_iconblk[i].ib_ptext];
  65.    }
  66. #endif
  67.  
  68. #if NUM_TI != 0
  69.    for (i = 0; i < NUM_TI; i++)        /* tedinfo addresses */
  70.    {
  71.       rs_tedinfo[i].te_ptext  = rs_strings[(int) rs_tedinfo[i].te_ptext];
  72.       rs_tedinfo[i].te_ptmplt = rs_strings[(int) rs_tedinfo[i].te_ptmplt];
  73.       rs_tedinfo[i].te_pvalid = rs_strings[(int) rs_tedinfo[i].te_pvalid];
  74.    }
  75. #endif
  76.  
  77. #if NUM_OBS != 0
  78.    xscale = yscale = ytrim = 1;        /* initial values - not used */
  79.  
  80.    for (i = 0; i < NUM_OBS; i++)         /* objects */
  81.    {
  82.       object = &rs_object[i];             /* get object address */
  83.  
  84.       if (object->ob_next == NIL)         /* root of a tree? */
  85.       {
  86.      if (object->ob_state & OUTLINED)    /* is it outlined? */
  87.      {
  88.         xscale = gr_hwchar;             /* set proper x scale */
  89.         yscale = gr_hhchar;             /* same for y scale */
  90.         ytrim  = 16 / yscale;         /* compensate for bad scale */
  91.      }
  92.      else
  93.      {
  94.         /* use constants instead of gr_hxchar to get a nice picture */
  95.         /* on a color monitor (although it is bigger, it looks ok)    */
  96.  
  97.         xscale = 8;
  98.         yscale = 16;
  99.         ytrim  = 1;
  100.      }
  101.       }
  102.  
  103.       fixsize(object->ob_x,xscale,1);           /* fix x position */
  104.       fixsize(object->ob_y,yscale,ytrim);      /* same for y */
  105.       fixsize(object->ob_width,xscale,1);      /* horizontal size */
  106.       fixsize(object->ob_height,yscale,ytrim); /* vertical size */
  107.  
  108.       switch (object->ob_type)        /* action depends on type */
  109.       {
  110.       case G_BUTTON:            /* these use a string */
  111.       case G_STRING:
  112.       case G_TITLE:
  113.      object->ob_spec = rs_strings[(long) object->ob_spec];
  114.      break;
  115.  
  116.       case G_IMAGE:
  117.      object->ob_spec = (char *) &rs_bitblk[(long) object->ob_spec];
  118.      break;
  119.  
  120.       case G_ICON:
  121.      object->ob_spec = (char *) &rs_iconblk[(long) object->ob_spec];
  122.      break;
  123.  
  124.       case G_TEXT:            /* these all use a tedinfo */
  125.       case G_BOXTEXT:
  126.       case G_FTEXT:
  127.       case G_FBOXTEXT:
  128.      object->ob_spec = (char *) &rs_tedinfo[(long) object->ob_spec];
  129.      break;
  130.       }
  131.    }
  132. #endif
  133.  
  134. #if NUM_TREE != 0
  135.    for (i = 0; i < NUM_TREE; i++)    /* fix tree address */
  136.       rs_trindex[i] = (long) &rs_object[(int) rs_trindex[i]];
  137. #endif
  138. }
  139.  
  140.